Replace examples with those from the second edition of the AMUSE book#1227
Replace examples with those from the second edition of the AMUSE book#1227rieder wants to merge 8 commits intoamusecode:mainfrom
Conversation
|
To be done:
|
|
If we do want to keep (some of) the old examples around, they should be in some directory that makes it clear that these are archived, and not updated. If they are still useful, they should be moved to the new structure. |
|
I don't see how the tests would depend on the examples, but I'll go and do a local build and run them all to check. I think pip packages, the PDF, and more examples should be separate Issues, so if it doesn't break the tests then I'll merge this, even if it isn't perfect I doubt it'll make things worse. |
5d45632 to
28b8cda
Compare
LourensVeen
left a comment
There was a problem hiding this comment.
I've pushed a commit to move the examples to src/amuse_examples and add a forward in src/amuse/examples, and make the whole thing an installable package like the others.
Looking at it again, I think it's probably better to put the actual examples into a subdirectory src/amuse_examples/amuse_examples, so that there's nothing else in the directory. Then we can symlink that to /examples, and if anyone plays with it on the command line then they're less likely to mess up the package definitions.
I've run the tests and this didn't break anything, but then I ran the examples themselves and found many problems, which I've added comments for.
There was a problem hiding this comment.
Crashes with
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/2017arXiv170307029H_Fig3.py", line 48, in <module>
from distinct_colours import get_distinct
ModuleNotFoundError: No module named 'distinct_colours'
|
|
||
|
|
||
| def anim_gravity(filename="sun_venus_earth.amuse", **kwargs): | ||
| particles = read_set_from_file(filename) |
There was a problem hiding this comment.
Crashes here because the file is not found:
Traceback (most recent call last):
File "<string>", line 1, in <module>
from amuse.examples import run ; run('anim_gravity')
~~~^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
~~~~~~~~~~~~^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/anim_gravity.py", line 71, in main
anim_gravity(**kwargs)
~~~~~~~~~~~~^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/anim_gravity.py", line 45, in anim_gravity
particles = read_set_from_file(filename)
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/io/base.py", line 94, in read_set_from_file
raise IoException("Error: file '{0}' does not exist.".format(filename))
amuse.io.base.IoException: IO exception: Error: file 'sun_venus_earth.amuse' does not exist.
There was a problem hiding this comment.
Ah, I think this is actually produced by one of the other examples, so you need to run them in the right order, which likely isn't alphabetical.
There was a problem hiding this comment.
Fails to run using amuse.examples.run:
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
^^^^^^^^^^^^
AttributeError: module 'amuse_examples.cooling_class' has no attribute 'main'
There was a problem hiding this comment.
Fails to run using amuse.examples.run:
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
^^^^^^^^^^^^
AttributeError: module 'amuse_examples.gravity_hydro' has no attribute 'main'
There was a problem hiding this comment.
Fails to run using amuse.examples.run:
Traceback (most recent call last):
File "<string>", line 1, in <module>
from amuse.examples import run ; run('gravity_stellar_minimal')
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
~~~~~~~~~~~~^^
TypeError: main() missing 1 required positional argument: 'args'
There was a problem hiding this comment.
Fails to run using amuse.examples.run because it has no main() function.
There was a problem hiding this comment.
Won't run using amuse.examples.run:
Traceback (most recent call last):
File "<string>", line 1, in <module>
from amuse.examples import run ; run('supernova_grid')
~~~^^^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
~~~~~~~~~~~~^^
TypeError: main() missing 7 required positional arguments: 'stellar_mass', 'stellar_radius', 'core_mass', 'core_radius', 't_end', 'dt', and 'resolution'
There was a problem hiding this comment.
Fails because prepare_figure is missing.
There was a problem hiding this comment.
Crashes because we need to explicitly append to a file now:
Traceback (most recent call last):
File "<string>", line 1, in <module>
from amuse.examples import run ; run("three_body_bridge_order4m4")
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/__init__.py", line 55, in run
example.main()
~~~~~~~~~~~~^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse_examples/three_body_bridge_order4m4.py", line 76, in main
write_set_to_file(ss.savepoint(time), filename, 'hdf5', version='2')
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/io/base.py", line 75, in write_set_to_file
processor.store()
~~~~~~~~~~~~~~~^^
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/io/store.py", line 99, in store
processor = store_v2.StoreHDF(
self.filename,
...<4 lines>...
compression_opts=self.compression_opts
)
File "/home/lourens/.miniconda3/envs/amuse-pr-1227/lib/python3.14/site-packages/amuse/io/store_v2.py", line 738, in __init__
raise FileExistsError("Opening file for write with overwrite_file is False but file {0} exists".format(filename))
FileExistsError: Opening file for write with overwrite_file is False but file SunAndEarthAndMoon_TBB.h5 exists
| @@ -0,0 +1,55 @@ | |||
| from amuse.units import units | |||
| from amuse.community.seba import Seba | |||
| from seculartriple_tps import Seculartriple | |||
There was a problem hiding this comment.
seculartriple_tps is missing.
Existing examples are outdated, in some cases not working and often duplicated by others.
This replaces all examples from the "textbook", "syllabus" and "simple" directories with the complete set from the textbook (second edition).